package demo2;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Microsoft
 * Date: 2023-01-01
 * Time: 17:00
 */
class Money implements Cloneable{
    public double money = 12.25;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Student implements Cloneable{
    public String name;
    public Money m = new Money();

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //只是克隆了Student对象
        Student student = (Student)super.clone();
        //克隆了Student对象里面的Money对象
        student.m = (Money) this.m.clone();
        return student;
    }
    public boolean equals(Object obj){
        //判断是否为空指针
        if (obj == null) {
            return false ;
        }
        //判断this和obj是否指向同一个对象
        if(this == obj) {
            return true ;
        }
        //判断是否是不同物种之间进行比较，例如：Dog和Bird类
        if (!(obj instanceof Student)) {
            return false ;
        }

        Student student = (Student) obj;
        if(this.name.equals(student.name)){
            return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
class Person{
}
class Animal{
}
class Dog{
    void func1(){}
    void func2(){}
    void func3(){}
}
public class Test {
    public static void func(Object obj){

    }

    public static void main(String[] args) {
        Student student1 = new Student();
        Student student2 = new Student();

        student1.name = "123";
        student2.name = "123";
        System.out.println(student1);
        System.out.println(student2);
        System.out.println(student1 == student2);

        System.out.println(student1.equals(student2));

    }


}

//    public static void main2(String[] args)throws CloneNotSupportedException {
//        Student student = new Student();
//        Student student1 = (Student)student.clone();
//        System.out.println(student.m.money);
//        System.out.println(student1.m.money);
//        System.out.println("===============");
//        student.m.money = 99;
//        System.out.println(student.m.money);
//        System.out.println(student1.m.money);
//
//    }
//


//    public static void main2(String[] args) {
//        func(new Money());
//        func(new Person());
//        func(new Animal());
//        Dog dog= new Dog();
//        dog.func1();
//        dog.func2();
//        dog.func3();
//        System.out.println("============");
//        new Dog().func2();
//        new Dog().func3();
//        System.out.println(new Student());
//    }










